<template>
  <div class="dialog-box-container">
    <div class="chat-input">
      <div @keyup.enter="onClick" ref="editor" contenteditable class="inp"></div>
      <div @click="onClick" class="btn">
        <Icon type="upArrow"></Icon>
      </div>
    </div>
  </div>
</template>

<script>
import Icon from '@/components/Icon'
export default {
  props: {
  },
  components: {
    Icon
  },
  data() {
    return {
      editor: null,
      isEmpty: true
    }
  },
  computed: {
    isDisabled() {
      return this.isEmpty
    }
  },
  methods: {
    onClick() {
      this.$emit('submit', this.editor.textContent.trim() )
      this.editor.textContent = ''
    },
    handleInp() {
      this.$forceUpdate()
      if(this.editor.textContent.trim() === '') {
        console.log('空')
      } else {
        this.isEmpty = false
      }
    },
  },
  mounted() {
    this.editor = this.$refs.editor
    // this.editor.addEventListener('input', this.handleInp)
    // this.editor.addEventListener('keyup', this.handleInp)
    // this.editor.addEventListener('focus', this.handleInp)
  }
}
</script>

<style lang="less" scoped>
@import "~@/styles/mixin.less";
@import "~@/styles/var.less";

.dialog-box-container {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  width: 100%;
  height: 100%;
  overflow: hidden;
  padding: 16px;
  box-sizing: border-box;
}

// 输入框外层容器（控制整体布局与基础样式）
.chat-input {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 720px;
  background: #f5f7fa;
  border: 1px solid #e5e6eb;
  border-radius: 24px;
  padding: 8px 8px 8px 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-sizing: border-box;
  box-shadow: 7px 7px rgba(0, 0, 0, 0.12);

  // 容器 hover 交互
  &:hover {
    border-color: @cyber;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  }

  // 输入框样式（contenteditable 模拟）
  .inp {
    flex: 1;
    min-height: 40px;
    max-height: 60px;
    padding: 8px 0;
    outline: none;
    font-size: 28px;
    color: #1d2129;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
    overflow: scroll;
    scroll-behavior: smooth;
    scrollbar-width: none;
    

    // 占位符效果（contenteditable 伪元素实现）
    &:empty:before {
      content: '请输入对话内容...';
      color: #c9cdcf;
      pointer-events: none;
    }

    // 有内容时隐藏占位符
    &:not(:empty):before {
      content: none;
    }

    // 输入框聚焦时，同步激活按钮样式
    &:focus {
      &~.btn {
        background-color: @cyber;
        color: #fff;
      }
    }
  }

  // 提交按钮（字体图标专用样式）
  .btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: #fff;
    border: 1px solid #e5e6eb;
    color: @eva;
    font-size: 18px; // 控制字体图标大小
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);

    // 按钮 hover 效果
    &:hover {
      background-color: @cyber;
      border-color: @eva;
      color: #fff;
      font-size: 30px;
      transform: translateY(-2px);
    }

    // 按钮点击按压反馈
    &:active {
      transform: translateY(0);
      background-color: #66b1ff;
    }

    // 禁用状态（输入为空时可添加）
    &.disabled {
      cursor: not-allowed;
      background-color: @gray;
      border-color: #e5e6eb;
      color: #c9cdcf;

      &:hover {
        transform: none;
        background-color: @gray;
        border-color: #e5e6eb;
      }
    }
  }
}

</style>